package service

import (
	"gitee.com/lzqysoft/framework/services/base/models"
	"gitee.com/lzqysoft/framework/common"
	"gitee.com/lzqysoft/framework/services/base/lib/jwt"
	"gitee.com/lzqysoft/framework/common/log"
)

func CheckToken(token string) (reply *common.Result){
	user,org,token, err := models.GetJwt(token)
	if err != nil {
		reply.Code = "0004"
		reply.Message = "查询失败"
		return nil
	}
	log.Info(*user)
	log.Info(*org)
	log.Info(token)
	res := make(map[string]interface{})
	//u := *user
	res["user"] = user.Convert2Map()
	res["org"] = org.Convert2Map()
	res["token"] = token
	reply = &common.Result{}
	reply.Code = "0000"
	reply.Res = res
	return reply
}

func GenerateToken(userId, orgId string) string {
	et := jwt.EasyToken{
		Appid:"framework",
		Userid:userId,
		Orgid:orgId,
	}
	token, err := et.GetToken()
	if err != nil {
		return ""
	}
	return token
}